package cn.edu.scau.cmi.lishuoxin.client.experiment10;

import java.util.Date;

import cn.edu.scau.cmi.lishuoxin.interProgramming.experiment10.dao.UserDao;
import cn.edu.scau.cmi.lishuoxin.interProgramming.experiment10.domain.User;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;

public class Main extends Application{
	@Override
	public void start(Stage primaryStage) throws Exception {
		// TODO Auto-generated method stub
		try {
			UserDao dao = new UserDao();
			Pane root = new Pane();
			Button button1 = new Button("创建用户");
			button1.setOnAction(e -> {
				User user = new User();
				user.setId(32);
				user.setUsername("李明");
				user.setBirthday(new Date());
				user.setSex("男");
				user.setAddress("广州");
				dao.insertUser(user);
			});
			button1.setLayoutX(0);
			button1.setLayoutY(10.0);
			root.getChildren().add(button1);
			
			Button button2 = new Button("删除用户");
			button2.setOnAction(e -> {
				dao.deleteUser(31);
			});
			button2.setLayoutX(0);
			button2.setLayoutY(60.0);
			root.getChildren().add(button2);
			
			Button button3 = new Button("查找用户");
			button3.setOnAction(e -> {
				dao.selectUserById(1);
			});
			button3.setLayoutX(0);
			button3.setLayoutY(110.0);
			root.getChildren().add(button3);
			
			Button button4 = new Button("修改用户");
			button4.setOnAction(e -> {
				User user = new User();
				user.setId(31);
				user.setUsername("李明");
				user.setBirthday(new Date());
				user.setSex("男");
				user.setAddress("佛山");
				dao.updateUser(user);
			});
			button4.setLayoutX(0);
			button4.setLayoutY(160.0);
			root.getChildren().add(button4);
			
			Scene scene = new Scene(root,500,400);
			primaryStage.setTitle("ORM模式");
			primaryStage.setScene(scene);
			primaryStage.show();
		} catch(Exception e) {
			e.printStackTrace();
		}
	
	}
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		launch(args);
	}
}
